/**
 * Copyright (C)  Gadglet .
 *
 * This file is part of Gadglet
 *
 * Gadglet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gadglet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gadglet.client.gwt.ui;

import com.google.gwt.user.client.ui.ListBox;

/**
 * Simple ListBox control in a VerticalFormPanel
 *
 */
public class FormItemListBox  extends FormItem{
	private ListBox fieldControl = new ListBox();
	
	@Override
	public ListBox getFieldControl() {
		return fieldControl;
	}
	
	

	public FormItemListBox(String name, String title) {
		super(name, title);
		
		super.itemEntry.add(fieldControl);
	}

	/* (non-Javadoc)
	 * @see com.gadglet.client.gwt.ui.FormItem#getFieldValue()
	 */
	@Override
	public String getFieldValue() {
		
		return fieldControl.getValue(fieldControl.getSelectedIndex());
	}
	
	/**
	 * @param SelecteValue - set the selected value
	 */
	public void setSelectedByValue(String SelecteValue){
		if (SelecteValue != null) {
			for (int index = 0; index < fieldControl.getItemCount(); index++)
				if (fieldControl.getValue(index).equals(SelecteValue))
					fieldControl.setSelectedIndex(index);
		}
	}

	/* (non-Javadoc)
	 * @see com.gadglet.client.gwt.ui.FormItem#setFieldControlValue(java.lang.String)
	 */
	@Override
	public void setFieldControlValue(String selectedValue) {
		setSelectedByValue(selectedValue);
		
	}



	/* (non-Javadoc)
	 * @see com.gadglet.client.gwt.ui.FormItem#setControlWidth(java.lang.String)
	 */
	@Override
	public void setControlWidth(String width) {
		fieldControl.setWidth(width);
		
	}
	
}
